﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.NeighborUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import flash.filters.*;
    import Display.*;
    import flash.text.*;
    import Classes.inventory.*;
    import Modules.stats.experiments.*;
    import Display.aswingui.*;
    import Modules.stats.types.*;

    public class FriendBar extends JPanel {

        public static const SLOT_WIDTH:int = 70;

        private static var m_populateNeighborsFlag:Boolean = true;

        protected const BLANK_FRIEND_INTERVAL:int = 6;
        protected const BLANK_FRIEND_INITIAL:int = 8;
        protected const Y_POS:int = 345;

        public var m_slots:Array;
        public var m_nghbrActionsMenuCreated:Boolean;
        protected var m_friendscroll:FriendBarScrollingList;
        private var m_startX:int;
        protected var m_preload:Boolean = false;

        public function FriendBar(){
            this.m_slots = [];
            super(new FlowLayout(FlowLayout.LEFT, 4, 5, true));
            this.m_nghbrActionsMenuCreated = false;
        }
        private function makeNavs():void{
        }
        public function get preload():Boolean{
            return (this.m_preload);
        }
        public function set preload(_arg1:Boolean):void{
            this.m_preload = _arg1;
        }
        protected function onSlotClick(_arg1:FriendBarSlotEvent):void{
            var _local2:FriendCell = _arg1.slot;
            _arg1.stopImmediatePropagation();
            _arg1.stopPropagation();
            if (((_local2.uid) && (!((_local2.uid == Global.player.uid))))){
                dispatchEvent(new FriendBarSlotEvent(FriendBarSlotEvent.FRIEND_BAR_SLOT_CLICK, _local2, _arg1.friendPoint, "friendbar", "contextual", "slot"));
            };
        }
        protected function onGiftClick(_arg1:FriendBarSlotEvent):void{
            var _local2:FriendCell = _arg1.slot;
            if (_local2.uid != Global.player.uid){
                dispatchEvent(new FriendBarSlotEvent(FriendBarSlotEvent.FRIEND_BAR_GIFT_CLICK, _local2, _arg1.friendPoint, "friendbar", "contextual", "slot"));
            };
        }
        protected function onVisitClick(_arg1:FriendBarSlotEvent):void{
            var _local2:FriendCell = _arg1.slot;
            if (_local2.uid != Global.player.uid){
                dispatchEvent(new FriendBarSlotEvent(FriendBarSlotEvent.FRIEND_BAR_VISIT_CLICK, _local2, _arg1.friendPoint, "friendbar", "contextual", "slot"));
            };
        }
        public function updateNeighbors(_arg1:Array):void{
            this.m_friendscroll.data = _arg1;
            this.m_friendscroll.moveRight(1);
            ASwingHelper.prepare(this);
        }
        public function friendVisited(_arg1:String):void{
            this.m_friendscroll.friendVisited(_arg1);
        }
        protected function onClickAddNeighbor(_arg1:MouseEvent):void{
            _arg1.stopImmediatePropagation();
            _arg1.stopPropagation();
            FrameManager.showTray("invite.php?ref=neighbor_ladder");
            StatsManager.sample(100, StatsCounterType.HUD_COUNTER, StatsKingdomType.NEIGHBOR_LADDER, "add_friends");
        }
        protected function makeLeftAddFriend():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -10);
            var _local2:DisplayObject = (new EmbeddedArt.emptyAvatar() as DisplayObject);
            ASwingHelper.setSizedBackground(_local1, _local2, new Insets(14));
            var _local3:Number = TextFieldUtil.getLocaleFontSize(13, 10, [{
                locale:"de",
                size:12
            }, {
                locale:"fr",
                size:14
            }, {
                locale:"es",
                size:12
            }]);
            var _local4:AssetPane = ASwingHelper.makeMultilineText(ZLoc.t("Main", "AddFriend"), 75, EmbeddedArt.TITLE_FONT, TextFormatAlign.CENTER, _local3, 0xFFFFFF, [new GlowFilter(0, 0.5, 3, 3, 10)]);
            _local1.appendAll(ASwingHelper.verticalStrut(82), _local4);
            _local1.addEventListener(MouseEvent.CLICK, this.onClickAddNeighbor, false, 0, true);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        public function addPlayerToFriends(_arg1:Array):void{
            var _local2:int;
            var _local3:Player;
            var _local8:int;
            var _local9:int;
            _arg1.reverse();
            var _local4:int = Global.player.xp;
            _local2 = 0;
            while (_local2 < _arg1.length) {
                _local3 = Global.player.findFriendById(_arg1[_local2].uid);
                if (((((_local3) && ((_arg1[_local2].xp > _local4)))) || ((_arg1[_local2].uid == "-2")))){
                    break;
                };
                _local2++;
            };
            var _local5:Friend = new Friend(Global.player.uid, Global.player.gold, Global.player.xp, Global.player.level, false, null, "", Global.player.snUser.picture, Global.player.snUser.firstName, null, Global.player.socialLevel, false, false);
            _arg1.splice(_local2, 0, _local5);
            var _local6 = -1;
            var _local7:Friend;
            _local8 = 0;
            while (_local8 < _arg1.length) {
                _local7 = _arg1[_local8];
                if (((!((_local7.m_uid == Global.player.uid))) && (_local7.m_firstTimeVisit))){
                    _local6 = _local8;
                    break;
                };
                _local8++;
            };
            if (_local6 >= 0){
                _local9 = ((_arg1.length - 1) - 5);
                if (_local9 >= _local6){
                    _arg1.splice(_local6, 1);
                    _arg1.splice(_local9, 0, _local7);
                };
            };
        }
        public function populateNeighbors(_arg1:Array, _arg2:Boolean=true):void{
            var _local8:Array;
            var _local9:int;
            var _local10:int;
            var _local11:int;
            var _local12:Friend;
            if (!m_populateNeighborsFlag){
                return;
            };
            m_populateNeighborsFlag = false;
            this.m_slots = [];
            this.addPlayerToFriends(_arg1);
            var _local3:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_ADDFRIEND_LHS);
            if (_local3 == ExperimentDefinitions.NORMAL_ADDFRIEND){
                _local8 = new Array();
                if (_arg1.length >= this.BLANK_FRIEND_INITIAL){
                    _local8.push(this.BLANK_FRIEND_INITIAL);
                };
                if ((_arg1.length - this.BLANK_FRIEND_INITIAL) > this.BLANK_FRIEND_INTERVAL){
                    _local10 = Math.floor(((_arg1.length - this.BLANK_FRIEND_INITIAL) / this.BLANK_FRIEND_INTERVAL));
                    _local11 = 0;
                    while (_local11 < _local10) {
                        _local8.push((((_local11 + 1) * this.BLANK_FRIEND_INTERVAL) + this.BLANK_FRIEND_INITIAL));
                        _local11++;
                    };
                };
                _local9 = 0;
                while (_local9 < _local8.length) {
                    _local12 = new Friend(null, 0, 0, 0, false, null, "", null, null, null, 0, true, true);
                    _arg1.splice(0, 0, _local12);
                    _local9++;
                };
            };
            var _local4:Dictionary = new Dictionary();
            _local4[Commodities.GOODS_COMMODITY] = Global.player.commodities.getCount(Commodities.GOODS_COMMODITY);
            _local4 = null;
            var _local5 = !(_arg2);
            var _local6:FriendBarLeftNav = new FriendBarLeftNav();
            _local6.addEventListener(FriendBarEvent.MOVE, this.onFriendBarMove);
            _local6.addEventListener(FriendBarEvent.MOVE_END, this.onFriendBarMoveEnd);
            this.append(ASwingHelper.horizontalStrut(1));
            this.append(_local6);
            this.append(ASwingHelper.horizontalStrut(3));
            this.append(this.makeLeftAddFriend());
            this.m_friendscroll = new FriendBarScrollingList(_arg1);
            this.append(this.m_friendscroll);
            this.m_friendscroll.addEventListener(FriendBarSlotEvent.FRIEND_BAR_SLOT_CLICK, this.onSlotClick, false, 0, true);
            this.m_friendscroll.addEventListener(FriendBarSlotEvent.FRIEND_BAR_GIFT_CLICK, this.onGiftClick, false, 0, true);
            this.append(ASwingHelper.horizontalStrut(1));
            var _local7:FriendBarRightNav = new FriendBarRightNav();
            _local7.addEventListener(FriendBarEvent.MOVE, this.onFriendBarMove);
            _local7.addEventListener(FriendBarEvent.MOVE_END, this.onFriendBarMoveEnd);
            this.append(_local7);
            ASwingHelper.prepare(this);
            ASwingHelper.prepare(this.getParent());
            dispatchEvent(new FriendBarEvent(FriendBarEvent.LOADED, undefined, (_arg1.length * FriendBar.SLOT_WIDTH)));
        }
        private function onFriendBarMove(_arg1:FriendBarEvent):void{
            if (_arg1.delta >= 0){
                this.m_friendscroll.moveRight(_arg1.length);
            } else {
                this.m_friendscroll.moveLeft(_arg1.length);
            };
        }
        public function get scrollingList():FriendBarScrollingList{
            return (this.m_friendscroll);
        }
        private function onFriendBarMoveEnd(_arg1:FriendBarEvent):void{
            if (_arg1.delta == 0){
                this.m_friendscroll.moveLeft(0);
            } else {
                this.m_friendscroll.moveRight(0);
            };
        }
        public function addPeddlerIconForFriend(_arg1:String):void{
            this.m_friendscroll.addfriendPeddlerIcon(_arg1);
        }
        public function hidePeddlerIcon(_arg1:String):void{
            this.m_friendscroll.hidePeddlerIcon(_arg1);
        }

    }
}//package Display.NeighborUI 
